// 获取滚动条的兼容
function getScrollTop(){
	return document.body.scrollTop || document.documentElement.scrollTop;
}
// 设置滚动条
function setScrollTop(s){
	document.body.scrollTop = s;
	document.documentElement.scrollTop = s;
}
// 点击小火箭,实现小火箭和滚动条同时上升

let r_pos;
let g_pos;
let rocket = document.querySelector(".rocket");
rocket.addEventListener("click",function(){
	rocket.classList.add("active");
	r_pos = rocket.offsetTop;
	g_pos = getScrollTop();
	r_step = r_pos/1000*50;
	g_step = g_pos/1000*50;
	rise();
	scrollUp();
})

// 小火箭上升
let r_step = 10;
let r_origin_pos = rocket.offsetTop;
function rise(){
	let timer = null;
	timer = setInterval(function(){
		r_pos = r_pos - r_step;
		rocket.style.top = r_pos+"px";
		if(r_pos<0){
			rocket.classList.remove("active")
			rocket.style.top = r_origin_pos+"px";
			clearInterval(timer);
			return;
		}
	},50)
}

// 滚动条上升
function scrollUp(){
	let g_step = 100;
	let timer = null;
	timer = setInterval(function(){
		g_pos = g_pos - g_step;
		setScrollTop(g_pos);
		if(g_pos<0){
			clearInterval(timer);
			return;
		}
	},50)
}